Fix crash with authenticator not initialized #16426
Open
+10
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

Closes WOOMOB-1830
Also closes WOOMOB-1836
Description
When migrating to UIScene lifecycle in #16230, we moved
AppCoordinatorfromAppDelegatetoUISceneDelegate. Since the authenticator is initialized as part ofAppCoordinator, the app can crash if a user launches the app while authenticated with site credentials. The crash chain is below:→ This calls restoreSessionSiteIfPossible() (DefaultStoresManager.swift:179)
→ Which calls restoreWordPressSite(with: url) (line 747)
→ Which calls WordPressAuthenticator.fetchSiteInfo (line 782)
→ 💥 CRASH: WordPressAuthenticator.shared wasn't initialized yet!
The solution is to move the initialization of the coordinator from AppCoordinator's configureAuthenticator to AppDelegate before initializeAfterDependenciesAreInitialized is triggered.
Test Steps
The crash is a timing issue - it requires that WordPressSiteAction.fetchSiteInfo returns almost immediately, triggering WordPressAuthenticator.fetchSiteInfo before SceneDelegate's done setting up AppCoordinator. So it's not straightforward to reproduce the crash.
The best bet is to use the debugger: add a breakpoint in the first line of DefaultStoresManager.restoreWordPressSite then do the following steps:
p WordPressAuthenticator.shared. You should see in Xcode console:error: Execution was interrupted, reason: EXC_BREAKPOINT (code=1, subcode=0x197309f0c). The process has been returned to the state before expression evaluation.Screenshots
N/A
RELEASE-NOTES.txtif necessary.